<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>{$sets['title']}</title>
  
  <!-- 添加初始化样式 -->
  <style>
    /* 默认隐藏所有加密内容 */
    body:not(.unlocked) [data-encrypt="1"] {
      display: none !important;
    }
  </style>

  <script>
    var js_sets_raw = {$sets|json_encode|raw};
    var js_classs_raw = {$classs|json_encode|raw};
    var js_datas_raw = {$datas|json_encode|raw};
    var js_icon = '/ico/get.php?url=';
    
    // 调试原始数据
    //console.log("原始数据 - sets:", js_sets_raw);
    //console.log("原始数据 - classs:", js_classs_raw);
    //console.log("原始数据 - datas:", js_datas_raw);
    
    // 安全地解析JSON或对象
    function safeEval(data, defaultType, varName) {
      // 检查数据是否为空
      if (!data || data === '""' || data === '{}' || data === '[]') {
        //console.warn(varName + " 数据为空");
        return defaultType === 'object' ? {} : [];
      }
      
      try {
        // 如果data已经是对象，直接返回
        if (typeof data === 'object' && data !== null) {
          //console.log(varName + " 已经是对象类型");
          return data;
        }
        
        // 确保data是字符串类型
        var dataStr = String(data);
        
        // 检查数据是否已经是引号包裹的JSON字符串
        if (dataStr.startsWith('"') && dataStr.endsWith('"')) {
          // 移除多余的引号并转义内部引号
          dataStr = dataStr.substring(1, dataStr.length - 1).replace(/\\"/g, '"');
        }
        
        // 尝试解析JSON
        var result = JSON.parse(dataStr);
        //console.log(varName + " 成功通过JSON.parse解析");
        return result;
      } catch(e) {
        //console.warn(varName + " JSON解析失败:", e.message);
        
        try {
          // 如果JSON解析失败，尝试使用Function构造函数（比eval更安全）
          var result = (new Function('return ' + data))();
          //console.log(varName + " 成功通过Function构造函数解析");
          return result;
        } catch(e2) {
          //console.error(varName + " 所有解析方法都失败:", e2.message);
          //console.error("问题数据:", data);
          
          // 如果都失败，返回默认值
          return defaultType === 'object' ? {} : [];
        }
      }
    }
    
    // 解析数据
    var js_sets = safeEval(js_sets_raw, 'object', 'js_sets');
    var js_classs = safeEval(js_classs_raw, 'array', 'js_classs');
    var js_datas = safeEval(js_datas_raw, 'array', 'js_datas');
    
    // 确保变量是对象
    js_sets = js_sets || {};
    js_classs = js_classs || [];
    js_datas = js_datas || [];
    
    // 输出解析后的数据
    //console.log("解析后 - js_sets:", js_sets);
    //console.log("解析后 - js_classs:", js_classs);
    //console.log("解析后 - js_datas:", js_datas);
    //console.log("js_icon:", js_icon);
  </script>
  <!-- IE11检测和资源加载 -->
  <script>
    // IE11检测
    var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
    
    // 调试信息
    console.log("浏览器检测: " + (isIE11 ? "IE11" : "现代浏览器"));
    
    // 动态加载CSS
    function loadCSS(url) {
      var link = document.createElement('link');
      link.rel = 'stylesheet';
      link.href = url;
      document.head.appendChild(link);
      console.log("加载CSS: " + url);
    }
    
    // 动态加载JS
    function loadJS(url, callback) {
      var script = document.createElement('script');
      script.src = url;
      if (callback) {
        script.onload = callback;
      }
      document.head.appendChild(script);
      console.log("加载JS: " + url);
    }
    
    // 根据浏览器类型加载不同资源
    if (isIE11) {
      // IE11专用资源
      loadCSS('/data/font-awesome.min.css');
      loadCSS('/static/css/ie11.css');
      
      // 基础JS库
      document.write('<script src="/data/jquery-3.5.1.min.js"><\/script>');
      document.write('<script src="/data/md5.min.js"><\/script>');
      
      // 确保页面加载完成后再加载IE11专用JS
      function loadIE11JS() {
        console.log("准备加载IE11专用JS");
        loadJS('/static/js/ie11.js', function() {
          console.log("IE11专用JS加载完成");
        });
      }
      
      // 使用多种方式确保JS加载
      if (window.addEventListener) {
        window.addEventListener('load', loadIE11JS);
      } else if (window.attachEvent) {
        window.attachEvent('onload', loadIE11JS);
      } else {
        window.onload = loadIE11JS;
      }
    } else {
      // 现代浏览器资源
      loadCSS('/data/bootstrap-4.6.2/css/bootstrap.min.css');
      loadCSS('/data/font-awesome.min.css');
      loadCSS('/static/css/style.css');
      
      // 基础JS库
      document.write('<script src="/data/jquery-3.5.1.min.js"><\/script>');
      document.write('<script src="/data/md5.min.js"><\/script>');
      document.write('<script src="/data/bootstrap-4.6.2/js/bootstrap.bundle.min.js"><\/script>');
      document.write('<script src="/static/js/main.js"><\/script>');
    }
  </script>
</head>

<body class="theme-dark">
  <div id="ie11-content" style="display:none;">
    <!-- IE11专用内容 -->
    
    <div class="ie11-container">
      <!-- IE11侧边栏 -->
      <div class="ie11-sidebar">
        <div class="ie11-sidebar-title">
          <img src="{$sets['logo1']}" alt="{$sets['title']}">
        </div>
        
        <ul class="ie11-menu" id="ie11-menu">
          <!-- 这里将由JavaScript生成菜单 -->
        </ul>
      </div>
      
      <!-- IE11主内容区 -->
      <div class="ie11-main">
        <div class="ie11-notice">
          您正在使用IE浏览器简化版，部分功能已禁用。为获得最佳体验，请使用现代浏览器。
        </div>
        <!-- IE11公告区域 -->
        <div class="ie11-notice" id="ie11-site-notice" style="display:none;">
          <i class="fa fa-volume-up"></i> <span id="ie11-notice-text"></span>
        </div>
        
        <!-- IE11搜索区域 -->
        <div class="ie11-search">
          <form id="ie11-search-form" class="ie11-search-form" action="" method="get" target="_blank">
            <div class="ie11-search-types">
              <div class="ie11-search-type">
                <input checked type="radio" name="type" id="ie11-type-baidu" value="https://www.baidu.com/s?wd=" data-placeholder="百度一下...">
                <label for="ie11-type-baidu"><span style="color:#1296db">百度</span></label>
              </div>
              <div class="ie11-search-type">
                <input type="radio" name="type" id="ie11-type-google" value="https://www.google.com/search?q=" data-placeholder="Google搜索...">
                <label for="ie11-type-google"><span style="color:#3B83FA">G</span><span style="color:#F3442C">o</span><span style="color:#FFC300">o</span><span style="color:#4696F8">g</span><span style="color:#2CAB4E">l</span><span style="color:#F54231">e</span></label>
              </div>
              <div class="ie11-search-type">
                <input type="radio" name="type" id="ie11-type-bing" value="https://cn.bing.com/search?q=" data-placeholder="Bing搜索...">
                <label for="ie11-type-bing"><span style="color:#007daa">Bing</span></label>
              </div>
            </div>
            <div class="ie11-search-input-container">
              <input type="text" id="ie11-search-input" class="ie11-search-input" name="q" placeholder="百度一下..." autocomplete="off">
              <button type="submit" class="ie11-search-button">
                <i class="fa fa-search"></i>
              </button>
            </div>
          </form>
        </div>
        
        <!-- IE11分类内容 -->
        <div id="ie11-categories-container">
          <!-- 这里将由JavaScript生成分类内容 -->
        </div>
        
        <!-- IE11页脚 -->
        <div class="ie11-footer">
          <div id="ie11-footer-content">
            <!-- 页脚内容将由JavaScript设置 -->
          </div>
        </div>
      </div>
    </div>
  </div>

  <div id="modern-content">
    <!-- 添加遮罩层 -->
    <div class="sidebar-overlay"></div>
    
    <!-- 移动端顶部菜单 -->
    <div class="d-sm-none mobile-header">
      <div class="mobile-logo">
        <img src="{$sets['logo2']}" alt="{$sets['title']}" id="mobile-logo-img">
      </div>
      <div class="circle-btn mobile-lock-btn">
        <i class="fa fa-lock"></i>
      </div>
      <div class="circle-btn mobile-theme-btn">
        <i class="fa fa-sun-o light-icon"></i>
        <i class="fa fa-moon-o dark-icon"></i>
      </div>
      <div class="circle-btn mobile-menu-btn">
        <i class="fa fa-bars"></i>
      </div>
    </div>
  
    <div class="container-fluid">
      <div class="row">
        <!-- PC端左侧菜单 -->
        <div class="sidebar">
          <div class="sidebar-content">
            <div class="logo-area d-none d-sm-block">
              <a href="/">
                <img src="{$sets['logo1']}" class="logo-expanded" alt="{$sets['title']}" id="pc-logo-img">
              </a>
            </div>
  
            <ul class="nav-menu" id="nav-menu-container">
              <!-- 这里将由JavaScript生成菜单 -->
            </ul>
          </div>
  
          <div class="sidebar-footer">
            <div class="circle-btn pc-lock-btn">
              <i class="fa fa-lock"></i>
            </div>
            <div class="circle-btn pc-theme-btn">
              <i class="fa fa-sun-o light-icon"></i>
              <i class="fa fa-moon-o dark-icon"></i>
            </div>
          </div>
        </div>
  
        <!-- 右侧内容区 -->
        <div class="main-content">
          <!-- 公告区域 - 仅在PC端且公告不为空时显示 -->
          <div class="notice-container d-none d-sm-flex" id="site-notice" style="display:none;">
            <div class="notice-icon">
              <i class="fa fa-volume-up"></i>
            </div>
            <div class="notice-text" id="notice-text">
              <!-- 公告内容将由JavaScript设置 -->
            </div>
          </div>
          
          <!-- 搜索区域 -->
          <div class="search-container">
            <form class="search-form" action="" method="get" target="_blank">
              <ul class="search-type">
                <li><input checked="" hidden="" type="radio" name="type" id="type-baidu" value="https://www.baidu.com/s?wd=" data-placeholder="百度一下..."><label for="type-baidu"><span style="color:#1296db">百度</span></label></li>
                <li><input hidden="" type="radio" name="type" id="type-google" value="https://www.google.com/search?q=" data-placeholder="Google搜索..."><label for="type-google"><span style="color:#3B83FA">G</span><span style="color:#F3442C">o</span><span style="color:#FFC300">o</span><span style="color:#4696F8">g</span><span style="color:#2CAB4E">l</span><span style="color:#F54231">e</span></label></li>
                <li><input hidden="" type="radio" name="type" id="type-bing" value="https://cn.bing.com/search?q=" data-placeholder="Bing搜索..."><label for="type-bing"><span style="color:#007daa">Bing</span></label></li>
                {if $sets['baidu_translate_show'] == 0}
                <li class="translate-item" id="translate-item" style="display:none;"><button id="fanyi" class="translate-button" type="button"><i class="fa fa-language"></i><span style="color:#4CAF50">翻译</span></button></li>
                {/if}
              </ul>
              <div class="search-input-container">
                <input type="text" class="search-input" name="q" placeholder="百度一下..." autocomplete="off">
                <button type="submit" class="search-button">
                  <i class="fa fa-search"></i>
                </button>
              </div>
              <!-- 添加站内搜索下拉框 -->
              <div class="search-dropdown"></div>
            </form>
          </div>
  
          <!-- 导航卡片容器 -->
          <div class="cards-container" id="cards-container">
            <!-- 这里将由JavaScript生成卡片内容 -->
          </div>
          
          <!-- 添加滚动提示元素 -->
          <div class="scroll-tip-container" id="scroll-tip-container">
            <div class="scroll-tip" id="scroll-tip">
              <i class="fa fa-arrow-up" id="scroll-tip-up"></i>
              <span id="scroll-tip-text">再次滚动切换到上一个分类</span>
              <i class="fa fa-arrow-down" id="scroll-tip-down"></i>
            </div>
          </div>
  
          <!-- 页脚 -->
          <footer class="footer">
            <div id="myfooter" class="footer-content">
              <!-- 页脚内容将由JavaScript设置 -->
            </div>
          </footer>
        </div>
      </div>
    </div>
  
    <!-- 自定义弹窗HTML结构 -->
    <div class="custom-modal" style="display:none;">
      <div class="custom-modal-overlay"></div>
      <div class="custom-modal-container">
        <div class="custom-modal-header">
          <h5 class="custom-modal-title"></h5>
          <button type="button" class="custom-modal-close">&times;</button>
        </div>
        <div class="custom-modal-body"></div>
        <div class="custom-modal-footer"></div>
      </div>
    </div>
    
    {if $sets['baidu_translate_show'] == 0}
    <!-- 添加翻译弹出框 -->
    <div class="translate-modal" id="translate-modal" style="display:none;">
      <div class="translate-modal-overlay"></div>
      <div class="translate-modal-container">
        <div class="translate-modal-header">
          <h5 class="translate-modal-title">简单在线翻译工具</h5>
          <button type="button" class="translate-modal-close">&times;</button>
        </div>
        <div class="translate-modal-body">
          <div class="translate-container">
            <!-- 输入框和输出框 -->
            <div class="translate-text-boxes">
              <textarea id="translate-input" placeholder="输入要翻译的内容..."></textarea>
              <textarea id="translate-output" readonly placeholder="翻译结果..."></textarea>
            </div>

            <!-- 按钮区域 -->
            <div class="translate-buttons">
              <select id="translate-language-select" class="translate-language-select">
                <option value="zh">中文</option>
                <option value="en">英文</option>
                <option value="jp">日文</option>
                <option value="kor">韩文</option>
                <option value="fra">法文</option>
                <option value="spa">西班牙文</option>
                <option value="ru">俄文</option>
              </select>
              <button id="translate-button" class="translate-action-button">翻译</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    {/if}
  </div>

  <script>
    // 根据浏览器类型显示对应内容 注意新加的代码要转移到main.js中，否则可能影响IE11的正常使用
    (function() {
      console.log("执行内容切换");
      if (isIE11) {
        document.getElementById('ie11-content').style.display = 'block';
        document.getElementById('modern-content').style.display = 'none';
        console.log("显示IE11内容");
      } else {
        document.getElementById('ie11-content').style.display = 'none';
        document.getElementById('modern-content').style.display = 'block';
        console.log("显示现代浏览器内容");
      }
      
      // 初始化页面内容
      initPageContent();
    })();
    
    // 初始化页面内容
    function initPageContent() {
      // 检查是否已解锁
      const storedPwd = localStorage.getItem('pwd');
      const sitePassword = js_sets.password;
      const isUnlocked = storedPwd && storedPwd === sitePassword;
      
      // 如果已解锁，添加unlocked类
      if (isUnlocked) {
        document.body.classList.add('unlocked');
      }
      
      // 设置基本信息
      document.title = js_sets.title || '导航';
      
      // 设置logo
      var pcLogoImg = document.getElementById('pc-logo-img');
      var mobileLogoImg = document.getElementById('mobile-logo-img');
      if (pcLogoImg) {
        pcLogoImg.src = js_sets.logo1 || '';
        pcLogoImg.alt = js_sets.title || '导航';
      }
      if (mobileLogoImg) {
        mobileLogoImg.src = js_sets.logo2 || '';
        mobileLogoImg.alt = js_sets.title || '导航';
      }
      
      // 设置公告
      if (js_sets.notice) {
        var noticeText = document.getElementById('notice-text');
        var siteNotice = document.getElementById('site-notice');
        var ie11NoticeText = document.getElementById('ie11-notice-text');
        var ie11SiteNotice = document.getElementById('ie11-site-notice');
        
        if (noticeText) noticeText.innerHTML = js_sets.notice;
        if (siteNotice) siteNotice.style.display = 'flex';
        if (ie11NoticeText) ie11NoticeText.innerHTML = js_sets.notice;
        if (ie11SiteNotice) ie11SiteNotice.style.display = 'block';
      }
      
      // 设置页脚
      var myfooter = document.getElementById('myfooter');
      var ie11FooterContent = document.getElementById('ie11-footer-content');
      if (myfooter) myfooter.innerHTML = js_sets.footer || '';
      if (ie11FooterContent) ie11FooterContent.innerHTML = js_sets.footer || '';
      
      {if $sets['baidu_translate_show'] == 0}
      // 设置翻译按钮
      var translateItem = document.getElementById('translate-item');
      if (translateItem) {
        // 设置加密属性
        if (js_sets.baidu_translate_encrypt == 1) {
          translateItem.setAttribute('data-encrypt', '1');
          // 根据解锁状态显示或隐藏
          translateItem.style.display = isUnlocked ? 'block' : 'none';
        } else {
          // 如果不需要加密，直接显示
          translateItem.style.display = 'block';
        }
      }
      {/if}
      
      // 生成菜单
      generateMenus();
      
      // 生成内容区域
      generateContent();
    }
    
    // 生成菜单
    function generateMenus() {
      var navMenuContainer = document.getElementById('nav-menu-container');
      
      // 检查是否已解锁
      const storedPwd = localStorage.getItem('pwd');
      const sitePassword = js_sets.password;
      const isUnlocked = (storedPwd && storedPwd === sitePassword) || window.tempUnlocked;
      
      // 清空现有内容
      if (navMenuContainer) navMenuContainer.innerHTML = '';
      
      // 遍历分类生成菜单
      js_classs.forEach(function(classItem) {
        if (classItem.parent_id == 0) {
          // 现代浏览器菜单
          if (navMenuContainer) {
            let menuHtml = '<li class="nav-item has-sub" data-id="' + classItem.id + '"';
            if (classItem.encrypt == 1) {
              menuHtml += ' data-encrypt="1"';
              if (!isUnlocked) {
                menuHtml += ' style="display:none;"';
              }
            }
            menuHtml += '>';
            menuHtml += '<a href="javascript:void(0)">';
            menuHtml += '<i class="fa ' + classItem.icon + '"></i>';
            menuHtml += '<span>' + classItem.title + '</span>';
            menuHtml += '</a>';
            menuHtml += '<ul class="sub-menu">';
            
            // 添加子菜单
            js_classs.forEach(function(subItem) {
              if (subItem.parent_id == classItem.id) {
                menuHtml += '<li';
                if (subItem.encrypt == 1) {
                  menuHtml += ' data-encrypt="1"';
                  if (!isUnlocked) {
                    menuHtml += ' style="display:none;"';
                  }
                }
                menuHtml += '>';
                menuHtml += '<a href="javascript:void(0)" data-id="' + subItem.id + '">';
                menuHtml += '<i class="fa ' + subItem.icon + '"></i>';
                menuHtml += '<span>' + subItem.title + '</span>';
                menuHtml += '</a>';
                menuHtml += '</li>';
              }
            });
            
            menuHtml += '</ul>';
            menuHtml += '</li>';
            
            navMenuContainer.innerHTML += menuHtml;
          }
        }
      });
      
      {if $sets['baidu_translate_show'] == 0}
      // 如果已解锁，显示翻译按钮
      if (isUnlocked) {
        var translateItem = document.getElementById('translate-item');
        if (translateItem) {
          translateItem.style.display = 'block';
        }
      }
      {/if}
    }
    
    // 生成内容区域
    function generateContent() {
      var cardsContainer = document.getElementById('cards-container');
      
      // 检查是否已解锁
      const storedPwd = localStorage.getItem('pwd');
      const sitePassword = js_sets.password;
      const isUnlocked = (storedPwd && storedPwd === sitePassword) || window.tempUnlocked;
      
      // 清空现有内容
      if (cardsContainer) cardsContainer.innerHTML = '';
      
      // 遍历分类生成内容
      js_classs.forEach(function(classItem) {
        if (classItem.parent_id == 0) {
          // 现代浏览器内容
          if (cardsContainer) {
            var contentHtml = '<div class="category-section" id="category-' + classItem.id + '"';
            if (classItem.encrypt == 1) {
              contentHtml += ' data-encrypt="1"';
              if (!isUnlocked) {
                contentHtml += ' style="display:none;"';
              }
            }
            contentHtml += '>';
            contentHtml += '<h2>' + classItem.title + '</h2>';
            contentHtml += '<div class="row">';
            
            // 添加当前主分类下的卡片
            js_datas.forEach(function(dataItem) {
              if (dataItem.class == classItem.id) {
                contentHtml += generateCardHtml(dataItem, classItem.encrypt == 1 && !isUnlocked);
              }
            });
            
            contentHtml += '</div>';
            
            // 添加二级分类及其卡片
            js_classs.forEach(function(subItem) {
              if (subItem.parent_id == classItem.id) {
                contentHtml += '<div class="sub-category-section" id="sub-category-' + subItem.id + '"';
                if (subItem.encrypt == 1) {
                  contentHtml += ' data-encrypt="1"';
                  if (!isUnlocked) {
                    contentHtml += ' style="display:none;"';
                  }
                }
                contentHtml += '>';
                contentHtml += '<h2>' + subItem.title + '</h2>';
                contentHtml += '<div class="row">';
                
                // 添加当前二级分类下的卡片
                js_datas.forEach(function(dataItem) {
                  if (dataItem.class == subItem.id) {
                    contentHtml += generateCardHtml(dataItem, (subItem.encrypt == 1 || classItem.encrypt == 1) && !isUnlocked);
                  }
                });
                
                contentHtml += '</div>';
                contentHtml += '</div>';
              }
            });
            
            contentHtml += '</div>';
            
            cardsContainer.innerHTML += contentHtml;
          }
        }
      });
    }
    
    // 生成卡片HTML
    function generateCardHtml(dataItem, shouldHide) {
      var html = '<div class="col-6 col-sm-4 col-md-3 col-lg-2"';
      if (dataItem.encrypt == 1 || shouldHide) {
        html += ' data-encrypt="1"';
        if (shouldHide) {
          html += ' style="display:none;"';
        }
      }
      html += '>';
      html += '<div class="nav-card">';
      html += '<a href="' + dataItem.url + '" target="_blank">';
      html += '<div class="card-icon">';
      
      if (!dataItem.icon) {
        html += '<img data-src="' + js_icon + dataItem.url + '" data-default="./images/favicon.png" src="./images/favicon.png">';
      } else {
        html += '<img data-src="' + dataItem.icon + '" data-default="./images/favicon.png" src="./images/favicon.png">';
      }
      
      html += '</div>';
      html += '<div class="card-content">';
      html += '<h3>' + dataItem.title + '</h3>';
      html += '<p>' + dataItem.mtitle + '</p>';
      html += '</div>';
      html += '</a>';
      html += '</div>';
      html += '</div>';
      
      return html;
    }
  </script>
</body>

</html>